package com.example.web.validation;

import com.example.web.dto.DatePageQuery;
import com.example.web.validation.annotation.DatePageQueryCheck;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;


public class DatePageQueryValidator implements ConstraintValidator<DatePageQueryCheck, DatePageQuery> {

    @Override
    public void initialize(DatePageQueryCheck constraintAnnotation) {

    }

    @Override
    public boolean isValid(DatePageQuery query, ConstraintValidatorContext context) {
        return query.getStart() == null && query.getEnd() == null
                || query.getStart() == null && query.getEnd() != null
                || query.getStart() != null && query.getEnd() == null
                || query.getStart() != null && query.getEnd() != null
                && query.getStart().getTime() <= query.getEnd().getTime();
    }

}
